package com.healthcloud.service.accompany.impl;

import com.healthcloud.dao.accompany.AccompanyBpDao;
import com.healthcloud.entity.HlDoctorEntity;
import com.healthcloud.entity.accompany.AccompanyBpEntity;
import com.healthcloud.entity.accompany.AccompanyBpVo;
import com.healthcloud.service.HlDoctorService;
import com.healthcloud.service.accompany.AccompanyBpService;
import com.healthcloud.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.healthcloud.utils.PageParam;
import org.springframework.transaction.annotation.Transactional;



@Service("accompanyBpService")
@Transactional
public class AccompanyBpServiceImpl implements AccompanyBpService {
	@Autowired
	private AccompanyBpDao accompanyBpDao;

	@Autowired
	private HlDoctorService hlDoctorService;
	
	@Override
	public AccompanyBpVo queryObjectVo(Long id){
		return accompanyBpDao.queryObjectVo(id);
	}
	
	@Override
	public List<AccompanyBpVo> queryListVo(AccompanyBpVo entity, PageParam pageParam){
		return accompanyBpDao.queryListVo(entity, pageParam);
	}
	
	@Override
	public int queryTotalVo(AccompanyBpVo entity){
		return accompanyBpDao.queryTotalVo(entity);
	}
	
	@Override
	public void save(AccompanyBpEntity accompanyBp){
		accompanyBpDao.save(accompanyBp);
	}
	
	@Override
	public void update(AccompanyBpEntity accompanyBp){
		accompanyBpDao.update(accompanyBp);
	}
	
	@Override
	public void delete(Integer id){
		accompanyBpDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		accompanyBpDao.deleteBatch(ids);
	}

	@Override
	public void saveOrUpdate(AccompanyBpEntity entity) {
		if (entity.getId()==null){
			saveByDoctor(entity);
		}else {
			update(entity);
		}
	}

	private void saveByDoctor(AccompanyBpEntity accompanyBp) {
		Long userId = ShiroUtils.getUserId();
		HlDoctorEntity doctor = hlDoctorService.queryByUserId(userId);
		if (doctor!=null){
			accompanyBp.setDoctorId(doctor.getId());
		}
		save(accompanyBp);
	}

	@Override
	public List queryRemindList(AccompanyBpVo entity, PageParam pageParam) {
		return accompanyBpDao.queryRemindList(entity, pageParam);
	}

	@Override
	public Integer queryRemindTotal(AccompanyBpVo entity) {
		return accompanyBpDao.queryRemindTotal(entity);
	}

}
